<?php $this->pageTitle="FitZone - Service Request"; ?>

<h1>Service Request Form</h1>
<?php if(Yii::app()->user->hasFlash('service_message')){ ?>

<div class="flash-success">
	<?php echo Yii::app()->user->getFlash('service_message'); ?>
</div>

<?php } ?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'service-form',
	'enableAjaxValidation'=>true,
	'clientOptions' => array('validateOnSubmit' => true,
   							 'validateOnChange' => false)

)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
	<fieldset>
	<legend>Store Details</legend>
	
<div class="row">
	<?php echo CHtml::label("Choose Store",'storeSelector'); ?>
	<?php 
			  $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
			     'name'=>'storeSelector',
			     'sourceUrl'=>array('ajaxSearchStore'),
				 // additional javascript options for the autocomplete plugin
			     'options'=>array(
			         'showAnim'=>'fold',
              		 'minLength'=>2,
                     'select'=>'js:function(event,ui){
                     	$("#Service_storeId").val(ui.item.id);
                     	$("#storeAddress").html(ui.item.address);
                     	$("#storeCity").html(ui.item.city);
                     	$("#storeState").html(ui.item.state);
                     	$("#storePostcode").html(ui.item.postcode);
                     	$("#storeContactPerson").html(ui.item.contactName);
                     	$("#storePhone").html(ui.item.contactPhone);
                     	$("#storeEmail").html(ui.item.contactEmail);
                     	$("#storeInfo").show("slow");
                     }',
				  ),
			      'htmlOptions'=>array(
			      	'style'=>'width:300px;'  
			       ),
			  ));
    ?>
    <?php echo $form->hiddenField($model,'storeId'); ?>
    <div class="hint">Input 2 letters of the store name or code to select a store</div>
	</div>

	<div id="storeInfo" style="display: none;">
	
	<div class="row">
		<?php echo CHtml::label('Street Address:', 'storeAddress');?>
		<?php echo CHtml::tag('span',array('id'=>'storeAddress'),'');?>
	</div>

	<div class="row">
		<?php echo CHtml::label('City/Town:', 'storeCity');?>
		<?php echo CHtml::tag('span',array('id'=>'storeCity'),'');?>
	</div>


	<div class="row">
		<?php echo CHtml::label('State:', 'storeState');?>
		<?php echo CHtml::tag('span',array('id'=>'storeState'),'');?>
	</div>
	
	<div class="row">
		<?php echo CHtml::label('Postcode:', 'storePostcode');?>
		<?php echo CHtml::tag('span',array('id'=>'storePostcode'),'');?>
	</div>
	
	<div class="row">
		<?php echo CHtml::label('Contact Person:', 'storeContactPerson');?>
		<?php echo CHtml::tag('span',array('id'=>'storeContactPerson'),'');?>
	</div>
	
	<div class="row">
		<?php echo CHtml::label('Store Phone:', 'storePhone');?>
		<?php echo CHtml::tag('span',array('id'=>'storePhone'),'');?>
	</div>

	<div class="row">
		<?php echo CHtml::label('Store Email:', 'storeEmail');?>
		<?php echo CHtml::tag('span',array('id'=>'storeEmail'),'');?>
	</div>
	
	</div><!-- End of Store Infomation. -->
			
	</fieldset>
	
	<fieldset>
	<legend>Customer Details</legend>
	
	<div class="row">
		<?php echo CHtml::label('Item at store:', 'itemAtStore');?>
		<?php echo CHtml::checkBox('itemAtStore');?>
	</div>	
	<?php 
Yii::app()->clientScript->registerScript("setItemAtStore",'
	$("#itemAtStore").change(function(eventArgs){
	var checked=eventArgs.target.checked;
	if(checked){
		$("#'.CHtml::activeId($model, "firstName").'").val("(Store)");
		$("#'.CHtml::activeId($model, "LastName").'").val($("#storeSelector").val());
		$("#'.CHtml::activeId($model, "address").'").val($("#storeAddress").html());
		$("#'.CHtml::activeId($model, "suburb").'").val($("#storeCity").html());
		$("#'.CHtml::activeId($model, "postcode").'").val($("#storePostcode").html());
		$("#'.CHtml::activeId($model, "state").'").val($("#storeState").html());
		$("#'.CHtml::activeId($model, "workPhone").'").val($("#storePhone").html());
		$("#'.CHtml::activeId($model, "email").'").val($("#storeEmail").html());
	}else{
		$("#'.CHtml::activeId($model, "firstName").'").val("");
		$("#'.CHtml::activeId($model, "LastName").'").val("");
		$("#'.CHtml::activeId($model, "address").'").val("");
		$("#'.CHtml::activeId($model, "suburb").'").val("");
		$("#'.CHtml::activeId($model, "postcode").'").val("");
		$("#'.CHtml::activeId($model, "state").'").val("");
		$("#'.CHtml::activeId($model, "workPhone").'").val("");
		$("#'.CHtml::activeId($model, "email").'").val("");
	}
	});
');
	?>
	
	<div class="row">
		<?php echo $form->labelEx($model,'firstName'); ?>
		<?php echo $form->textField($model,'firstName',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'firstName'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'LastName'); ?>
		<?php echo $form->textField($model,'LastName',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'LastName'); ?>
	</div>
	
		<div class="row">
		<?php echo $form->labelEx($model,'address'); ?>
		<?php echo $form->textField($model,'address',array('size'=>55,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'address'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'suburb'); ?>
		<?php echo $form->textField($model,'suburb',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'suburb'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'postcode'); ?>
		<?php echo $form->textField($model,'postcode',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'postcode'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'state'); ?>
		<?php echo $form->dropDownList($model,'state', DataUtil::getStates()); ?>
		<?php echo $form->error($model,'state'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'homePhone'); ?>
		<?php echo $form->textField($model,'homePhone',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'homePhone'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'workPhone'); ?>
		<?php echo $form->textField($model,'workPhone',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'workPhone'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'mobile'); ?>
		<?php echo $form->textField($model,'mobile',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'mobile'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'email'); ?>
		<?php echo $form->textField($model,'email',array('size'=>55,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'email'); ?>
	</div>
<?php /**	
	<div class="row">
		<?php echo $form->labelEx($model,'stairs'); ?>
		<?php echo $form->dropDownList($model,'stairs',DataUtil::getOptionYesNoEmpty()); ?>
		<?php echo $form->error($model,'stairs'); ?>
	</div> **/?>

	</fieldset>
	<!-- Customer details end -->
	
	<fieldset>
	<legend>Product Details</legend>
	
	<div class="row">
		<?php echo CHtml::label("Select Category", 'product_category'); ?>
		<?php echo CHtml::dropDownList('product_category', '', 
					Product::getProductTypes(),
					array('id'=>'product_category',
						  'ajax' => array(
							'type'=>'POST', //request type
							'url'=>Yii::app()->createUrl('site/ajaxSearchProductModel'), //url to call
							'update'=>'#Service_productId', //selector to update
							//'data'=>'js:javascript statement'
							//leave out the data key to pass all form values through
							),
						  'empty'=>'',
			)); ?>
		<?php echo $form->error($model,'email'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'productId'); ?>
		<?php echo $form->dropDownList($model,'productId',array()); ?>
		<?php echo $form->error($model,'productId'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'serialNo'); ?>
		<?php echo $form->textField($model,'serialNo',array('size'=>55,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'serialNo'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'purchaseDate'); ?>
		<?php echo $form->hiddenField($model,'purchaseDate'); ?>
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		    'name'=>'purchaseDateSelect',
		    'options'=>array(
				'altField'=>'#'.CHtml::activeId($model, "purchaseDate"),				
		    ),		   
		));
		?>
		<?php echo $form->error($model,'purchaseDate'); ?>
	</div>
	
	
	<div class="row">
		<?php echo $form->labelEx($model,'customerAccountNo'); ?>
		<?php echo $form->textField($model,'customerAccountNo',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'customerAccountNo'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'storeTinNo'); ?>
		<?php echo $form->textField($model,'storeTinNo',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'storeTinNo'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'warranty'); ?>
		<?php echo $form->dropDownList($model,'warranty',DataUtil::getOptionYesNoEmpty()); ?>
		<?php echo $form->error($model,'warranty'); ?>
	</div>	
	
	<div class="row">
		<?php echo $form->labelEx($model,'faultDescription'); ?>
		<?php echo $form->textArea($model,'faultDescription',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'faultDescription'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'otherInstruction'); ?>
		<?php echo $form->textArea($model,'otherInstruction',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'otherInstruction'); ?>
	</div>
	</fieldset>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->